package adapter;

import quoc.phu.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ContactAdapter extends BaseExpandableListAdapter {

	private Context context;
	private ContactList data;
	public ContactAdapter(Context context, ContactList data){
		this.context=context;
		this.data=data;
	}
	@Override
	public Object getChild(int groupPosition, int childPosition) {
		return data.getMember(groupPosition, childPosition);
	}

	@Override
	public long getChildId(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getChildView(int groupPos, int childPos,boolean isLastChild, View convertView, ViewGroup parent) {
		if (convertView == null) {
		    LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		    convertView = inflater.inflate(R.layout.row_contact_member, null);
		   }
		    
		   TextView tvPlayerName = (TextView) convertView.findViewById(R.id.txtName);
		   tvPlayerName.setText(data.getMember(groupPos, childPos).getTenDangNhap());
		    
		   return convertView;
	}

	@Override
	public int getChildrenCount(int groupIndex) {
		return this.data.getData().get(groupIndex).getMemberList().size();
	}

	@Override
	public Object getGroup(int groupIndex) {
		// TODO Auto-generated method stub
		return this.data.getGroup(groupIndex);
	}

	@Override
	public int getGroupCount() {
		return this.data.getSize();
	}

	@Override
	public long getGroupId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
		    View convertView, ViewGroup parent) {
		 
		   if (convertView == null) {
		    LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		    convertView = inflater.inflate(R.layout.row_contac_group, null);
		   }
		    
		   TextView tvGroupName = (TextView) convertView.findViewById(R.id.txtGroupName);
		   tvGroupName.setText(data.getGroup(groupPosition).getTenNhom());
		    
		   return convertView;
		  }

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition , int childPosition) {
		
		return true;
	}

	
	
}
